using System.Collections.Generic;
using System.Web.UI;

namespace Eneta.Portal.Forum.Controls.Common
{
    /// <summary>
    /// Summary description for SharePointToolBarItem.
    /// </summary>
    internal class SharePointToolBarItem
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SharePointToolBarItem"/> class.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="link">The link.</param>
        public SharePointToolBarItem(string title, string link)
        {
            if (title == null || link == null)
                return;

            Title = title;
            Link = link;
        }

        /// <summary>
        /// Gets or sets the link.
        /// </summary>
        /// <value>The link.</value>
        public string Link { get; set; }

        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        public string Title { get; set; }
    }

    /// <summary>
    /// Summary description for SharePointToolBar.
    /// </summary>
    public class SharePointToolBar
    {
        private readonly string _userName;
        private readonly List<SharePointToolBarItem> _items = new List<SharePointToolBarItem>();

        /// <summary>
        /// Initializes a new instance of the <see cref="SharePointToolBar"/> class.
        /// </summary>
        public SharePointToolBar(string userName)
        {
            if (userName == null)
                return;

            _userName = userName;
        }

        /// <summary>
        /// Renders the specified output.
        /// </summary>
        /// <param name="output">The output.</param>
        public void Render(HtmlTextWriter output)
        {
            if (output == null)
                return;

            var count = 0;
            /*
            output.Write("<table width=100% class=\"ms-toolbar\" border=0 height=25 cellpadding=0 cellspacing=0>");
            output.Write("<tr>");
            output.Write("<tr>");
            output.Write("<td width=\"50%\" align=\"left\">");
            output.Write("<table>");
            output.Write("<tr>");
            output.Write(string.Format("<td>Welcome {0}</td>", _userName));
            output.Write("</tr>");
            output.Write("</table>");
            output.Write("</td>");
            output.Write("<td width=\"50%\" align=\"right\">");
            output.Write("<table>");
            output.Write("<tr>");

            foreach (var toolBarItem in _items)
            {
                output.Write(string.Format("<td><span><a href=\"{0}\">{1}</a></span>", toolBarItem.Link, toolBarItem.Title));
                if (++count < _items.Count)
                    output.Write("&nbsp;|&nbsp;");
                output.Write("</td>");
            }
            output.Write("</tr>");
            output.Write("</table>");
            output.Write("</td>");
            output.Write("</tr>");
            output.Write("</table>");
             */
        }

        /// <summary>
        /// Adds the item.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="link">The link.</param>
        public void AddItem(string title, string link)
        {
            if (title == null || link == null)
                return;

            _items.Add(new SharePointToolBarItem(title, link));
        }
    }
}